<?php

namespace App\Console\Commands;

use App\Jobs\TestJob;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;

class TestJobDb extends Command
{
    use DispatchesJobs;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'testJobDb {--queue=}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '简单消息队列生产者';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $options = $this->options();
        $queueName = $this->option('queue');
        $this->info(json_encode($options));
        $this->info(json_encode($queueName));

        $this->info('通过命令行执行消息队列任务');

        // 分发任务
        for ($i = 1; $i <= 10; $i++) {
            $this->dispatch((new TestJob($i))->onQueue('test'));
        }
    }
}
